import { defineStore } from 'pinia'
import { StatusEnum } from '@/enums/httpEnum'
import { getSharingList } from '@/api/resource'
import { message as Message } from 'ant-design-vue'
import { SharingListParams } from '@/api/model/resourceModel'
import { BasicResponseModel } from '@/api/model/basicModel'

export const useResourceStore = defineStore({
  id: 'app-resource',
  state: () => ({
    sharingList: <BasicResponseModel>{}
  }),
  getters: {
    // getSharingList(): BasicResponseModel {
    //   return this.sharingList
    // }
  },
  actions: {
    async getSharingList(params: SharingListParams) {
      const res = await getSharingList(params)
      const { status, message } = res
      if (status === StatusEnum.ERROR) {
        Message.error(message)
      }
      if (status === StatusEnum.SUCCESS) {
        this.sharingList = res
      }
      return this.sharingList // 返回 newValue || oldValue
    }
  }
})
